﻿using Mes.Domain.BoundedContext.Entities.WorkOrders;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Mes.Infrastructure.Data.BoundedContext.EntityTypeConfigurations.WorkOrders
{
    public class JobEntityConfig : IEntityTypeConfiguration<Job>
    {
        public void Configure(EntityTypeBuilder<Job> builder)
        {
            builder.ToTable("job");
            builder.HasKey(b => new { b.Wo_Id, b.Oper_Id });
            builder.Property(b => b.Wo_Id).HasMaxLength(40).IsRequired();
            builder.Property(b => b.Oper_Id).HasMaxLength(40).IsRequired();
            builder.Property(b => b.Job_Desc).HasMaxLength(80);
            builder.Property(b => b.Item_Id).IsRequired();
            builder.Property(b => b.State_Cd).IsRequired().IsRequired();
            builder.Property(b => b.Job_Priority).IsRequired();
            builder.Property(b => b.Req_Finish_Time_Utc);
            builder.Property(b => b.Req_Finish_Time_Local);
            builder.Property(b => b.Init_Sched_Ent_Id).IsRequired();
            builder.Property(b => b.Target_Sched_Ent_Id).IsRequired();
            builder.Property(b => b.Run_Ent_Id);
            builder.Property(b => b.Qty_Reqd).IsRequired();
            builder.Property(b => b.Qty_Prod).IsRequired();
            builder.Property(b => b.Qty_Prod_Erp);
            builder.Property(b => b.Qty_Rejected).IsRequired();
            builder.Property(b => b.Qty_Rejected_Erp);
            builder.Property(b => b.Qty_At_Start).IsRequired();
            builder.Property(b => b.Deviation_Above).IsRequired();
            builder.Property(b => b.Deviation_Below).IsRequired();
            builder.Property(b => b.Batch_Size).IsRequired();
            builder.Property(b => b.Uom_Id);
            builder.Property(b => b.First_Job).IsRequired();
            builder.Property(b => b.Final_Job).IsRequired();
            builder.Property(b => b.Sched_Pinned).IsRequired();
            builder.Property(b => b.Check_Inv).IsRequired();
            builder.Property(b => b.Est_Fixed_Lab);
            builder.Property(b => b.Est_Lab_Rate);
            builder.Property(b => b.Est_Setup_Time);
            builder.Property(b => b.Est_Teardown_Time);
            builder.Property(b => b.Est_Prod_Rate).IsRequired();
            builder.Property(b => b.Prod_Uom).IsRequired();
            builder.Property(b => b.Est_Transfer_Time);
            builder.Property(b => b.Sched_Start_Time_Utc);
            builder.Property(b => b.Sched_Start_Time_Local);
            builder.Property(b => b.Latest_Start_Time_Utc);
            builder.Property(b => b.Latest_Start_Time_Local);
            builder.Property(b => b.Sched_Finish_Time_Utc);
            builder.Property(b => b.Sched_Finish_Time_Local);
            builder.Property(b => b.Act_Start_Time_Utc);
            builder.Property(b => b.Act_Start_Time_Local);
            builder.Property(b => b.Act_Finish_Time_Utc);
            builder.Property(b => b.Act_Finish_Time_Local);
            builder.Property(b => b.Concurrent_Link).IsRequired();
            builder.Property(b => b.Job_Cost);
            builder.Property(b => b.Parent_Contingent_Job).IsRequired();
            builder.Property(b => b.Child_Contingent_Job).IsRequired();
            builder.Property(b => b.Notes);
            builder.Property(b => b.Assoc_File).HasMaxLength(254);
            builder.Property(b => b.Assoc_File_Type).HasMaxLength(254);
            builder.Property(b => b.Status_Notes).HasMaxLength(1700);
            builder.Property(b => b.Display_Seq).IsRequired();
            builder.Property(b => b.Folder_Ver_Id).HasMaxLength(40);
            builder.Property(b => b.Rework).IsRequired();
            builder.Property(b => b.Rework_Cd).HasMaxLength(40);
            builder.Property(b => b.Rework_Process_Id).HasMaxLength(40);
            builder.Property(b => b.Spare1).HasMaxLength(80);
            builder.Property(b => b.Spare2).HasMaxLength(80);
            builder.Property(b => b.Spare3).HasMaxLength(80);
            builder.Property(b => b.Spare4).HasMaxLength(80);
            builder.Property(b => b.Last_Edit_Comment).HasMaxLength(254);
            builder.Property(b => b.Edited_By).HasMaxLength(40);
            builder.Property(b => b.Edit_Time).IsRequired();
            builder.Property(b => b.Row_Id).IsRequired().UseIdentityColumn().HasIdentityOptions(startValue: 0, incrementBy: 1, minValue: 0);
        }
    }
}
